package xyz.cerberu.cet.anime.domain;

import com.bete.MD5Utils;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.solr.client.solrj.beans.Field;
import xyz.cerberu.cet.global.utils.TimeUtils;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.Date;
import java.time.LocalDate;

/**
 * @Name β世界
 * Created on 23:49
 * @Description 动漫的实体对象
 */
public class Anime implements Serializable {
    /** 动漫id **/
    @Field("ani_id")
    private String ani_id;
    /** 动漫名字 **/
    @Field("anime_name")
    private String anime_name;
    /** 动漫的URL编码 **/
    @Field("anime_url")
    private String anime_url;
    /** 动漫的官网 **/
    @Field("website")
    private String website;
    /** 动漫别名 **/
    @Field("alias")
    private String alias;
    /** 动漫的介绍 **/
    @Field("introducation")
    private String introducation;
    /** 封面的链接 **/
    @Field("cover")
    private String cover;
    /** 动漫季度 **/
    @Field("quarter")
    private String quarter;
    /** 所处年月日 **/
    @Field("year")
    private int year;
    /** 动漫更新的周期 **/
    @Field("week")
    private int week;
    /** 更新的日期 **/
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @Field("update_Time")
    private Date update_Time;

    /**
     * @author β世界 on 21:12 2020/9/11
     * 根据动漫名字+动漫别名+季度和年月日算出MD5的值，这个就是这个动漫的ID
     **/
    public void setAni_id() {
        ani_id = MD5Utils.stringToMD5(anime_name+alias+year+quarter+week);
    }

    public void setAni_id(String ani_id){
        this.ani_id = ani_id;
    }

    public void setAnime_name(String anime_name) {
        this.anime_name = anime_name;
    }

    public void setAnime_url(String anime_url) {
        this.anime_url = anime_url;
    }

    /**
     * @author β世界 on 15:04 2020/9/9
     * 设置anime_url(根据动漫名字进行URLEncode)
     **/
    public void setAnime_url() throws UnsupportedEncodingException {
        anime_url = URLEncoder.encode(anime_name,"UTF-8");
    }

    public void setWebsite(String website) {
        this.website = website;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public void setIntroducation(String introducation) {
        this.introducation = introducation;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public void setQuarter(String quarter) {
        this.quarter = quarter;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public void setWeek(int week) {
        this.week = week;
    }

    public void setUpdate_Time(Date update_Time) {
        this.update_Time = update_Time;
        LocalDate localDate = update_Time.toLocalDate();
        // 设置更新的年月日
        setYear(localDate.getYear());
        // 计算年月日
        quarter = TimeUtils.calculateQuarter(localDate.getMonthValue());
        // 设置更新的周期
        week = localDate.getDayOfWeek().getValue();
    }

    public String getAni_id() {
        return ani_id;
    }

    public String getAnime_name() {
        return anime_name;
    }

    public String getAnime_url() {
        return anime_url;
    }

    public String getWebsite() {
        return website;
    }

    public String getAlias() {
        return alias;
    }

    public String getIntroducation() {
        return introducation;
    }

    public String getCover() {
        return cover;
    }

    public String getQuarter() {
        return quarter;
    }

    public int getYear() {
        return year;
    }

    public int getWeek() {
        return week;
    }

    public Date getUpdate_Time() {
        return update_Time;
    }

    @Override
    public String toString() {
        return "Anime{" +
                "ani_id='" + ani_id + '\'' +
                ", anime_name='" + anime_name + '\'' +
                ", anime_url='" + anime_url + '\'' +
                ", website='" + website + '\'' +
                ", alias='" + alias + '\'' +
                ", introducation='" + introducation + '\'' +
                ", cover='" + cover + '\'' +
                ", quarter='" + quarter + '\'' +
                ", year='" + year + '\'' +
                ", week=" + week +
                ", update_Time=" + update_Time +
                '}';
    }

    public Anime() {
    }

    public Anime(String ani_id, String anime_name, String anime_url, String website, String alias, String introducation, String cover, String quarter, int year, int week, Date update_Time) {
        this.ani_id = ani_id;
        this.anime_name = anime_name;
        this.anime_url = anime_url;
        this.website = website;
        this.alias = alias;
        this.introducation = introducation;
        this.cover = cover;
        this.quarter = quarter;
        this.year = year;
        this.week = week;
        this.update_Time = update_Time;
    }
}
